# -*- coding:utf-8 -*-
# 子进程无返回值
from multiprocessing import Pool as Pool
import time


def func(x):
    print('msg:', x)
    time.sleep(2)
    print('end:')


if __name__ == '__main__':
    pool = Pool(processes=3)
    out1 = 'g:/1.txt'
    for i in range(1, 5):
        msg = 'hello %d' % (i)
        pool.apply_async(func, (msg,))  # 非阻塞
        # pool.apply(func,(msg,))       # 阻塞,apply()源自内建函数，用于间接的调用函数，并且按位置把元祖或字典作为参数传入。
        # pool.imap(func,[msg,])        # 非阻塞, 注意与apply传的参数的区别
        # pool.map(func, [msg, ])       # 阻塞

    print('Mark~~~~~~~~~~~~~~~')
    pool.close()
    pool.join()  # 调用join之前，先调用close函数，否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束
    print('sub-process done')
